package com.itheima.d1_map_impl;

import com.sun.tools.javac.Main;

import java.util.Comparator;
import java.util.TreeMap;

/*
    目标：掌握TreeMap集合的使用。

    需求：创建一个TreeMap集合，键是学生对象(Student)，值是籍贯(String)。
           学生属性姓名和年龄，按照年龄进行排序并遍历。

           TreeMap 是红黑树的排序规则保证了key的不重复
 */
public class Test3TreeMap {
    public static void main(String[] args) {
        TreeMap<Student, String> map = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getScore(), o2.getScore());
            }
        });
        map.put(new Student("001","贾宝玉",90.2),"1321");
        map.put(new Student("002","贾宝",90.1),"1321");
        map.put(new Student("003","贾玉",90.0),"1321");
        map.put(new Student("004","宝玉",89),"1321");
        System.out.println(map);
    }
}
